package com.base.common.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * User: jay.zhoujingjie Date: 13-12-31 Time: 下午2:48
 */
public class LogFactoryUtils {

	/**
	 * 返回LOG
	 * 
	 * @param className
	 *            "com.domain.className"
	 * @return
	 * @author jay.zhoujingjie
	 */
	public static Log getLog(String className) {
		return LogFactory.getLog(className);
	}

	/**
	 *
	 * @param cls
	 *            "class cls"
	 * @return
	 */
	public static Log getLog(Class cls) {
		return LogFactory.getLog(cls);
	}

	/**
	 * 获取异常堆栈信息
	 * 
	 * @param throwable
	 * @return
	 */
	public static String getPrintStackException(Throwable throwable) {
		String result = "";
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		try {
			sw = new StringWriter();
			pw = new PrintWriter(sw);
			throwable.printStackTrace(pw);
			result = sw.toString();
		} finally {
			try {
				if (sw != null) {
					sw.flush();
					sw.close();
				}
				if (pw != null) {
					pw.flush();
					pw.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
		return result;
	}

}
